import Vue from 'vue'
import VueRouter from 'vue-router'
import views from "@/views";
import interviewEcharts2 from "@/views/interviewEcharts2";

const Index = () => import('views/index.vue')
const InterviewEcharts = () => import('views/interviewEcharts')
const InterviewEcharts2 = () => import('views/interviewEcharts2')
const Home = () => import('views/home.vue')
const Blogs = () => import('views/blogs.vue')
const Community = () => import('views/community.vue')
const Community1 = () => import('views/community1.vue')
const Community2 = () => import('views/community2.vue')
const Interview = () => import('views/interview.vue')
const types = () => import('views/types.vue')
const users = () => import('views/users.vue')
const Login = () => import('views/login.vue')
const ArticleDetail = () => import('views/articleDetail.vue')
const InterviewDetail = () => import('views/interviewDetail.vue')
const Personal = () => import('views/personal.vue')
const ArticleDetail2 = () => import('views/articleDetail2.vue')

Vue.use(VueRouter)

const routes = [
    {path: '/', redirect: '/index'},
    {
        path: '/index',
        component: Index,
        redirect: '/home',
        children: [
            {path: '/home', component: Home},
            {path: '/blogs', component: Blogs},
            {path: '/community', name: "community", component: Community},
            {path: '/community1', name: "community1", component: Community1},
            {path: '/community2', name: "community2", component: Community2},
            {path: '/interview', name: "interview", component: Interview},
            {path: '/interviewEcharts', name: "interviewEcharts", component: InterviewEcharts},
            {path: '/interviewEcharts2', name: "interviewEcharts2", component: InterviewEcharts2},
            {path: '/types', name: "types", component: types},
            {path: '/users', name: "users", component: users},
            {path: '/article/:id', name: 'article', component: ArticleDetail},
            {path: '/interview/:id', name: 'interdetail', component: InterviewDetail},
            {path: '/personal/:id', name: 'personal', component: Personal},
            {path: '/article2/:id', name: 'article2', component: ArticleDetail2},
        ]
    },
    {path: '/login', component: Login}
]

const router = new VueRouter({
    mode: 'history',
    base: process.env.BASE_URL,
    routes
})

router.beforeEach((to, from, next) => {
    if (to.path === '/login') return next();
    // 如果没有token则直接返回登录界面
    // const tokenStr = window.localStorage.getItem("tokenValue")
    // if (!tokenStr) return next('/login')
    next()
})

export default router
